﻿@model IList<XCode.Membership.VisitStat>
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using System.Web.Mvc;
@using System.Web.Mvc.Ajax;
@using System.Web.Mvc.Html;
@using System.Web.Routing;
@{
    var fact = ViewBag.Factory as IEntityOperate;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as IList<FieldItem>;
    var set = ViewBag.PageSetting as PageSetting;

    var level = (XCode.Statistics.StatLevels)page["Level"].ToInt();
}
<div class="kt-widget4" style="overflow-x:auto;">
    <table class="table table-striped table-bordered table-hover table-checkable kt-datatable__table">
        <thead>
            <tr class="kt-datatable__row">
                @if (set.EnableSelect)
                {
                    <th class="kt-datatable__cell--center kt-datatable__cell kt-datatable__cell--check" style="width:20px;">
                        <lable class="kt-checkbox kt-checkbox--single kt-checkbox--all kt-checkbox--solid">
                            <input type="checkbox" id="chkAll" title="全选" />
                            <span></span>
                        </lable>
                    </th>
                }
                <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Time"))">时间</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Page"))">页面</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Title"))">标题</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Times"))">次数</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Users"))">用户</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("IPs"))">IP</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Error"))">错误</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Cost"))">平均耗时</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("MaxCost"))">最大耗时</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("CreateTime"))">创建时间</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("UpdateTime"))">更新时间</a></th>
                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <th class="text-center">操作</th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var entity in Model)
            {
                var st = new VisitStatModel
                {
                    Level = level,
                    Time = entity.Time
                };
                <tr>
                    @if (set.EnableSelect)
                    {
                        <td class="text-center" style="width:20px;">
                            <label class="kt-checkbox kt-checkbox--single kt-checkbox--all kt-checkbox--solid">
                                <input type="checkbox" name="keys" value="@entity.ID" />
                                <span></span>
                            </label>
                        </td>
                    }
                    <td class="text-center hidden-md hidden-sm hidden-xs">@entity.ID</td>
                    <td class="text-right">@st</td>
                    <td>@entity.Page</td>
                    <td>@entity.Title</td>
                    <td class="text-right">@entity.Times.ToString("n0")</td>
                    <td class="text-right">@entity.Users.ToString("n0")</td>
                    <td class="text-right">@entity.IPs.ToString("n0")</td>
                    <td class="text-right">@entity.Error.ToString("n0")</td>
                    <td class="text-right">@entity.Cost.ToString("n0") ms</td>
                    <td class="text-right">@entity.MaxCost.ToString("n0") ms</td>
                    <td>@entity.CreateTime.ToFullString("")</td>
                    <td>@entity.UpdateTime.ToFullString("")</td>
                    @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                    {
                        <td class="text-center" style="width: 50px;">
                            @Html.Partial("_List_Data_Action", (Object)entity)
                        </td>
                    }
                </tr>
            }
            @if (page.State != null)
            {
                var entity = page.State as VisitStat;
                <tr>
                    @if (set.EnableSelect)
                    {
                        <td></td>
                    }
                    <td class="text-center hidden-md hidden-sm hidden-xs">总计</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="text-right">@entity.Times.ToString("n0")</td>
                    <td class="text-right">@entity.Users.ToString("n0")</td>
                    <td class="text-right">@entity.IPs.ToString("n0")</td>
                    <td class="text-right">@entity.Error.ToString("n0")</td>
                    <td class="text-right">@entity.Cost.ToString("n0") ms</td>
                    <td class="text-right">@entity.MaxCost.ToString("n0") ms</td>
                    <td>@entity.CreateTime.ToFullString("")</td>
                    <td>@entity.UpdateTime.ToFullString("")</td>
                    @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                    {
                        <td></td>
                    }
                </tr>
            }
        </tbody>
    </table>
</div>